#include "widget.h"
#include "ui_widget.h"
#include<QHBoxLayout>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    setWindowTitle("Qt绘图框架测试:QPainter类");
    Parea=new painterarea;
    lb1=new QLabel("绘制形状:",this);

    cb=new QComboBox(this);
    cb->addItem("Line",painterarea::Line);
    cb->addItem("Rectangle",painterarea::Rectangle);


    connect(cb,static_cast<void (QComboBox::*)(int)>(&QComboBox::activated),this,&Widget::setPictureSlot);
    layout=new QGridLayout;

    layout->addWidget(lb1,0,0);
    layout->addWidget(cb,0,1);

    QHBoxLayout *mainlayout=new QHBoxLayout(this);
    mainlayout->addWidget(Parea); // 向布局添加控件
    mainlayout->addLayout(layout); // 向整体布局添加布局

    setPictureSlot(cb->currentIndex());


}

Widget::~Widget()
{
    delete ui;
}

void Widget::setPictureSlot(int index)
{
    painterarea::shape p=static_cast<painterarea::shape>(cb->currentIndex());
    Parea->myShape(p);
}

